<?php
require_once(WCF_DIR.'lib/page/AbstractPage.class.php');
require_once(WCF_DIR.'lib/page/util/menu/PageMenu.class.php');

/**
 * @author	Marco Daries
 * @copyright	2009 MaDa-Network.de
 * @website	www.mada-network.de
 *
 * FlashIRC is a freeware by lightIRC <http://lightirc.com/>
 */
 
class FlashIRCPage extends AbstractPage {
	// system
	public $templateName = 'flashIRC';
	
	// FlashIRC
	public $host = '';
	public $port = '';
	public $policyPort = '';
	public $ident = 'flashirc';
	public $language = '';
	public $nickselect = 'no';
	public $nickselectSuggestion = '';
	public $nick = '';
	public $soundAlerts = 'no';
	public $autojoin = '';
	public $perform = '';
	public $height = 0;
	public $styleURL = '';
	
	public function readParameters() {
		parent::readParameters();
		
		// Server
		$this->host = FLASHIRC_HOST;
		$this->port = FLASHIRC_PORT;
		$this->policyPort = FLASHIRC_POLICYPORT;
		
		// Language
		$this->language = LANGUAGE_CODE;
		
		// Nick
		if(!FLASHIRC_NICKSELECT) {
			$this->nickselect	= 'yes';
			if(WCF::getUser()->userID) $this->nickselectSuggestion = WCF::getUser()->username;
			else $this->nickselectSuggestion = FLASHIRC_NICK;
		} else {
			if(WCF::getUser()->userID) $this->nick = WCF::getUser()->username;
			else $this->nick = FLASHIRC_NICK;
		}
		
		// Channels
		$channels = explode("\n", FLASHIRC_AUTOJOIN);
		$channelString = "";
		foreach ($channels as $channel) {
			$channelString .= ((empty($channelString)) ? ('') : (',')).trim($channel);
		}
		$this->autojoin = $channelString;
		
		// Performs
		$performs = explode("\n", FLASHIRC_PERFORM);
		$performString = "";
		foreach ($performs as $perform) {
			$performString .= ((empty($performString)) ? ('') : (',')).$perform;
		}
		$this->perform = $performString;
	
		// Sounds
		if(FLASHIRC_SOUNDALERTS) $this->soundAlerts = 'yes';
		
		// Height
		$this->height = FLASHIRC_HEIGHT;
		
		if(WCF::getUser()->userFlashIRCStyle) $this->styleURL = 'styles/flashIRC/'.WCF::getUser()->userFlashIRCStyle.'.swf';
		elseif (FLASHIRC_STYLE_SELECT) $this->styleURL = 'styles/flashIRC/'.FLASHIRC_STYLE_SELECT.'.swf';

	}
	
	/**
	 * @see Page::assignVariables()
	 */
	public function assignVariables() {
		parent::assignVariables();
		
		WCF::getTPL()->assign(array(
			'host' => $this->host,
			'port' => $this->port,
			'policyPort' => $this->policyPort,
			'ident' => $this->ident,
			'language' => $this->language,
			'nickselect' => $this->nickselect,
			'nickselectSuggestion' => $this->nickselectSuggestion,
			'nick' => $this->nick,
			'soundAlerts' => $this->soundAlerts,
			'autojoin' => $this->autojoin,
			'perform' => $this->perform,
			'height' => $this->height,
			'styleURL' => $this->styleURL
		));
	}

	/**
	 * @see Page::show()
	 */
	public function show() {
		// set active menu item
		PageMenu::setActiveMenuItem('wcf.header.menu.flashIRC');
		// check permission
		WCF::getUser()->checkPermission('user.flashIRC.canView');
		// check module options
		if (!MODULE_FLASHIRC) {
			throw new IllegalLinkException();
		}
		
		parent::show();
	}
}
?>